package cn.edu.xjtu.android.emoji_warfare_android.game;

import java.util.ArrayList;

import cn.edu.xjtu.android.emoji_warfare_android.engine.shape.Rectangle;
import cn.edu.xjtu.android.emoji_warfare_android.engine.worker.DelayedOperation;
import cn.edu.xjtu.android.emoji_warfare_android.game.hero.Boss;
import cn.edu.xjtu.android.emoji_warfare_android.game.hero.Enemy;

/**
 * EnemyLoader<br>
 * 敌人加载器
 * 
 * @author wyyf
 *
 */
public class EnemyLoader extends DelayedOperation {

    /**
     * 第几波
     */
    public int waveIndex;

    /**
     * 是否加载敌人
     */
    boolean isLoading = true;

    Engine engine;

    ArrayList<Enemy> enemies;

    public EnemyLoader(Engine engine) {
        waveIndex = 1;
        this.setDelayMillis(1000 * 5);
        this.engine = engine;
        enemies = new ArrayList<Enemy>();
    }

    @Override
    public boolean run() {
        if (isLoading) {
            if (waveIndex % 10 == 0) {
                // 上Boss
                Boss b = new Boss(waveIndex / 10 + 1, new Rectangle(-225, -150, 225, 150));
                b.basePoint.x = 1080 / 2;
                b.basePoint.y = 200;
                engine.Layers.Enemy.add(b);
                enemies.add(b);
                isLoading = false;
            } else {
                // 上普通敌人
                int num = (int) (Math.random() * 4 + 2);
                for (int i = 0; i < num; i++) {
                    Enemy e = new Enemy(waveIndex, engine);
                    e.basePoint.x = 1080 / num * i + Config.Hero.radius;
                    e.basePoint.y = -Config.Hero.radius;
                    engine.Layers.Enemy.add(e);
                    enemies.add(e);
                }
            }
            waveIndex++;
        }

        return false;
    }

}
